﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WebKpiPage.Data.util
{
    public class SelectRegionOnly
    {
        // 类型: extent or polygon
        public string regionType;

        // 区域边界		
        public RegionBound bound;

        // 多边形点[目前只是选取第一个rings]
        public pointList map_points;


    }

    public struct point
    {
        public double x;
        public double y;
    }

    public class pointList
    {
        public int length;
        public List<point> source = new List<point>();

        // 给定坐标是否在线路上
        public bool PtInList(double x, double y, double tolerance)
        {
            double x1, y1, x2, y2;

            for (int i = 1; i < source.Count - 1; i++)
            {
                //2点确定一个矩形
                if (source[i].x > source[i - 1].x)
                {
                    x1 = source[i - 1].x;
                    x2 = source[i].x;
                }
                else
                {
                    x1 = source[i].x;
                    x2 = source[i - 1].x;
                }

                if (source[i].y > source[i - 1].y)
                {
                    y1 = source[i - 1].y;
                    y2 = source[i].y;
                }
                else
                {
                    y1 = source[i].y;
                    y2 = source[i - 1].y;
                }

                x1 -= tolerance;
                x2 += tolerance;
                y1 -= tolerance;
                y2 += tolerance;

                if ((x >= x1) && (x <= x2) &&
                    (y >= y1) && (y <= y2))
                    return true;
            }

            return false;
        }

    }
}
